package com.tanhua.config.template;

import com.baidu.aip.face.AipFace;
import com.tanhua.config.properties.AipProperties;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;

public class AipTemplate {

    @Autowired
    private AipFace aipFace;

    public boolean detect(String imageUrl) {
        // 可选：设置代理服务器地址, http和socket二选一，或者均不设置
//            client.setHttpProxy("proxy_host", proxy_port);  // 设置http代理
//            client.setSocketProxy("proxy_host", proxy_port);  // 设置socket代理
        // 调用接口

        String imageType = "URL";

        HashMap<String, String> options = new HashMap<>();
        options.put("face_field", "age");
        options.put("max_face_num", "2");
        options.put("face_type", "LIVE");
        options.put("liveness_control", "NONE");
        // 人脸检测
        JSONObject res = aipFace.detect(imageUrl, imageType, options);
        return "0".equals(res.get("error_code").toString());
    }
}
